const {
  addExp,
  getExpList,
  delExp,
  updateExp,
  selExp,
  selTchExping,
  selTchExped,
  selStuExping,
  selStuExped,
  selStuExpInfo,
  selExpByName,
  tSelExpByName,
  getExpingStu,
  updateStuMark,
  endExp,
  startExp,
  selExpAllMark,
  joinExp,
  isJoin,
  uploadWord,
  uploadFj,
} = require("../controller/exp");
const { SuccessModel, ErrorModel } = require("../model/resModel");
var express = require("express");
var router = express.Router();

const jwt = require("jsonwebtoken");
const loginCheck = require("../middleware/loginCheck");
const authCheck = require("../middleware/authCheck");
/* GET users listing. */

router.post("/add_exp", (req, res, next) => {
  // console.log(req.body);
  const result = addExp(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("添加失败"));
    }
  });
});

router.get("/get_exp", function (req, res, next) {
  const result = getExpList();
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/del_exp", (req, res, next) => {
  const result = delExp(req.query.id);
  // console.log(req.query.id);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel(val));
    } else {
      res.json(new ErrorModel("删除失败"));
    }
  });
});
router.post("/update_exp", function (req, res, next) {
  // console.log(req.query.id, req.body);
  const result = updateExp(req.query.id, req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
router.get("/sel_exp", function (req, res, next) {
  const result = selExp(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/sel_t_eing", function (req, res, next) {
  // console.log(req.query.id);
  const result = selTchExping(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/sel_t_eed", function (req, res, next) {
  // console.log(req.query.id);
  const result = selTchExped(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});

router.get("/sel_s_eing", function (req, res, next) {
  const result = selStuExping(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/sel_s_eed", function (req, res, next) {
  // console.log(req.query.id);
  const result = selStuExped(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.post("/sel_s_e_i", function (req, res, next) {
  console.log(req.body);
  const result = selStuExpInfo(req.body);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.post("/sel_e_bn", function (req, res, next) {
  console.log(req.body);
  const result = selExpByName(req.body);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.post("/tsel_e_bn", function (req, res, next) {
  console.log(req.body);
  const result = tSelExpByName(req.body);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/get_eing_s", function (req, res, next) {
  const result = getExpingStu(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.post("/update_s_mark", function (req, res, next) {
  // console.log(req.query.id, req.body);
  const result = updateStuMark(req.query.id, req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
router.get("/end_exp", function (req, res, next) {
  const result = endExp(req.query.id);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
router.get("/start_exp", function (req, res, next) {
  const result = startExp(req.query.id);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
//查询实验所以分数
router.get("/s_e_am", function (req, res, next) {
  const result = selExpAllMark(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});

router.post("/join_exp", (req, res, next) => {
  // console.log(req.body);
  const result = joinExp(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("添加失败"));
    }
  });
});
router.post("/is_join", function (req, res, next) {
  const result = isJoin(req.body);
  return result.then((val) => {
    if (val.sel_exp_id) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("没用选择"));
    }
  });
});

router.post("/eup_word", function (req, res, next) {
  const result = uploadWord(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
router.post("/eup_fj", function (req, res, next) {
  const result = uploadFj(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
module.exports = router;
